<?php
/**
 * -----------------------------------------------------
 *
 * models Region_model (地区)
 *
 * @package     models
 * @subpackage  
 * @category    Region_model
 * @author      ChenFu
 * @since       2014-7-25 version 1.0       
 * -----------------------------------------------------    
 */
class Region_model extends CI_Model
{
	private  $str_options;

	public function __construct()
	{
		parent::__construct();
        $this->load->database();
	}  

	// 根据id获取列表
	public function get_all_datelist($id){
		$this->db->where('pid',$id);
		$query = $this->db->get('xc_delivery_region');
		return $query->result_array();
	}

	// 根据id获取option列表
	public function get_datelist_option($pid=false,$id=false){
		// 查询数据
        $arr = $this->get_all_datelist($pid);
        foreach($arr as $rows){
            if($id == $rows['id']){
                $this->str_options.='<option value="'.$rows['id'].'" selected="selected" >|_'.$rows['name'].'</option>'; 
            }else{
                $this->str_options.='<option value="'.$rows['id'].'">|_'.$rows['name'].'</option>';
            }
        }
        return $this->str_options;
	}

	public function get_cate_name($cate_id){
	   $sql   = 'select * from xc_delivery_region where pid ='.$cate_id;
	   $query = $this->db->query($sql);
	   return $query->result_array();
	}

	public function get_address($array){
		$str_options ='';
		//查询数据
        $arr=$this->get_cate_name($array['cate_id']);
        foreach($arr as $rows)
        {
            if($array['id'] == $rows['id'])
            {
                $this->str_options.='<option value="'.$rows['id'].'"  selected="selected">|_&nbsp;'.$rows['name'].'</option>';
            }
            else
            {
                $this->str_options.='<option value="'.$rows['id'].'">|_&nbsp;'.$rows['name'].'</option>';
            }
        }
       return $this->str_options;
	}

	public function get_region_name_by_id($id){
	    $sql = "select * from xc_delivery_region where id=".$id;
        $query = $this->db->query($sql);
        if($query->num_rows() > 0){
            $arr = $query->row_array();
            return $arr['name'];
        }	
	}

}